package com.guli.edu.controller;


import com.guli.common.result.R;
import com.guli.edu.entity.form.VideoInfoForm;
import com.guli.edu.service.EduVideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.awt.SunGraphicsCallback;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author Daniel
 * @since 2019-03-29
 */
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService  ;

    @ApiOperation(value="添加小节")
    @PostMapping("saveVideo")
    public R addVideo(@RequestBody VideoInfoForm videoInfoForm){
        boolean flag = eduVideoService.saveVideo(videoInfoForm);
        if (flag) {
            return R.ok() ;
        }else {
            return R.error();
        }
    }

    @ApiOperation(value ="根据Id查询小节信息")
    @GetMapping("videoInfo/{id}")
    public R getVideoInfo(@PathVariable String id ){
        VideoInfoForm videoInfoForm = eduVideoService.getVideoInfo(id);
        return  R.ok().data("videoInfo",videoInfoForm);
    }

    @ApiOperation(value ="根据ID修改小节的方法")
    @PostMapping("updateVideo/{id}")
    public R updateVIdeById(@PathVariable String id ,@RequestBody VideoInfoForm videoInfoForm){
        boolean flag = eduVideoService.updateVideo(videoInfoForm);
        if (flag) {
            return R.ok() ;
        }else{
          return   R.error();
        }
    }

    @ApiOperation("删除小节的方法")
    @DeleteMapping("{id}")
    public R deleteVideo(@PathVariable String id  ){
       boolean  flag = eduVideoService.deleteVideoById(id);
        if (flag) {
            return R.ok() ;
        }else{
            return R.error();
        }

    }
    

}

